package n26;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static int removeDuplicates(int[] nums) {
        if (nums==null||nums.length==0){
            return 0;
        }
        Map<Integer,Integer> map = new HashMap<>();
        int maxLength = nums.length;

        for (int i = 0; i < maxLength; i++) {
            int num = nums[i];
            if (!map.containsKey(num)){
                map.put(num, num);

            }else{
                for (int j = i; j < maxLength-1; j++) {
                    nums[j] = nums[j+1];
                }
                i--;
                maxLength--;
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        int[] nums = {0,0,1,1,1,2,2,3,3,4};
        // int[] nums = {1,2,3,4};
        // int[] nums = {1,1,2};
        int i = removeDuplicates(nums);
        System.out.println(i);
        System.out.println(Arrays.toString(nums));
    }
}
